How to demonstrate the use of destructor in PHP | PHP programs
We will create a class with data members and implement a parameterized constructor and destructor.
<?php
class Sample
{
private $num1;
private $num2;
public function __construct($n1, $n2)
{
$this->num1 = $n1;
$this->num2 = $n2;
}
public function PrintValues()
{
echo "Num1: " . $this->num1 . "<br>";
echo "Num2: " . $this->num2 . "<br>";
}
public function __destruct()
{
echo "Destructor called";
}
}
$S = new Sample(30, 40);
$S->PrintValues();
?>


